package com.xxgc.vfc.common.error;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.net.InetAddress;
import java.net.UnknownHostException;

/*
 *
 *   @Author: Sjy
 *   @Date: 2023/11/8-11-08-14:26
 *   全局统一错误信息类
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ErrorMessage extends RuntimeException{
    //服务名称
    private String serviceName;
    //机器的ip地址
    private String iPAddress;
    //请求的url地址
    private String url;
    //运维状态码
    private String code;
    //错误信息
    private String message;
    //错误等级
    private Integer levels = 5;

    //修改错误等级
    public ErrorMessage levels(Integer levels){
        this.levels = levels;
        return this;
    }

    //生成构造函数
    public ErrorMessage(String code, String message) {
        //获取一下ip地址
        InetAddress ip = null;
        try {
            ip = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        this.iPAddress = ip.getHostAddress();
        this.code = code;
        this.message = message;
    }

    //静态获取错误信息
    public static ErrorMessage getErrorMessage(String code, String message) {
        return new ErrorMessage(code, message);
    }

}
